package byx.container.annotation.extension.core;

import byx.container.core.utils.CastUtils;

import java.lang.annotation.Annotation;
import java.util.Arrays;

public class AnnotationMetadata {
    private final Annotation[] annotations;

    public AnnotationMetadata(Annotation[] annotations) {
        this.annotations = annotations;
    }

    public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
        return Arrays.stream(annotations).anyMatch(a -> a.annotationType() == annotationType);
    }

    public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
        for (Annotation annotation : annotations) {
            if (annotation.annotationType() == annotationType) {
                return CastUtils.cast(annotation);
            }
        }
        return null;
    }
}
